package com.course.handler;

import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.script.RedisScript;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Component
public class RedisTemplateFactory extends StringRedisTemplate {

    public RedisTemplateFactory(RedisConnectionFactory lettuceConnectionFactory) {
        super(lettuceConnectionFactory);
    }

    @Resource(name = "MasterRedisTemplate")
    RedisTemplate<String,Object> masterRedisTemplate;

    /**
     * 获取主库的redisTemplate 执行lua脚本
     */
    public <T> T executeScript(RedisScript<T> script, List<String> keys, Object... args) {
        return masterRedisTemplate.execute(script, keys, args);
    }

}
